import {HttpUtils} from "@/utils/HttpUtils.ts";


export class AdminApi {

    static async login(form: LoginForm) {
        // 模拟长时间操作
        return await HttpUtils.mock<LoginVo>(() => {
            if (form.loginName === 'admin' && form.password === 'admin') {
                return {
                    "token": "mock-token",
                    "admin": {
                        "enId": "admin-en-id",
                        "code": "admin-code",
                        "username": "admin",
                        "nickname": "管理员",
                        "password": "admin",
                        "email": "admin@admin.com",
                        "avatar": "https://xsgames.co/randomusers/avatar.php?g=pixel&key=1",
                    },
                    "roles": [
                        {
                            "code": "admin",
                            "name": "管理员",
                            "enId": "admin-role-en-id",
                            "description": ""
                        },
                        {
                            "code": "user",
                            "name": "普通用户",
                            "enId": "user-role-en-id",
                            "description": ""
                        }
                    ]
                }
            }else {
                throw new Error("用户名或密码错误");
            }
        })
    }

    static async changeRole(roleCode: string) {
        // 模拟长时间操作
        return await HttpUtils.mock<ManageRule[]>(() => {
            if (roleCode === 'admin') {
                return [
                    {
                        code: 'dashboard',
                        title: "仪表盘",
                        path: "/dashboard",
                        icon: "DashboardFilled",
                        pcode: "0",
                    },
                    {
                        code: "dashboard-overview",
                        title: "首页概览",
                        path: "/dashboard/overview",
                        icon: "DashboardOutlined",
                        pcode: "dashboard",
                    },
                    {
                        code: "dashboard-statistics",
                        title: "数据统计",
                        path: "/dashboard/statistics",
                        icon: "DashboardOutlined",
                        pcode: "dashboard",
                    },
                    {
                        code: "system",
                        title: "系统管理",
                        path: "/system",
                        icon: "SettingFilled",
                        pcode: "0",
                    },
                    {
                        code: "system-admin",
                        title: "管理员管理",
                        icon: "fa fa-user",
                        path: "/system/admin",
                        pcode: "system",
                    },
                    {
                        code: "system-role",
                        title: "角色管理",
                        icon: "fa fa-users",
                        path: "/system/role",
                        pcode: "system",
                    },
                    {
                        code: "system-menu",
                        title: "菜单管理",
                        icon: "fa fa-list",
                        path: "/system/menu",
                        pcode: "system",
                    },
                    {
                        code: "table",
                        title: "表格示例",
                        icon: "TableOutlined",
                        path: "/table",
                        pcode: "0",
                    },
                    {
                        code: "table-basic",
                        title: "基础表格",
                        icon: "fa fa-table",
                        path: "/table/basic",
                        pcode: "table",
                    },
                ];
            } else if (roleCode === 'user') {
                return [];
            } else {
                throw new Error("角色不存在");
            }
        })
    }

}